﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DomainModel.Entities;
using System.IO;
using System.Web.Mvc;
using System.Web.Routing;

namespace WebCore.Helpers
{
    public class CalendarHelper : Controller
    {

        public MemoryStream BuildICS(Event item, string url)
        {
            
            var sb = new StringBuilder();

               

            sb.AppendLine("BEGIN:VCALENDAR");
            sb.AppendLine("VERSION:1.0");
            sb.AppendLine("BEGIN:VEVENT");
            sb.AppendLine("DTSTART:" + item.DateEvent.ToString("s"));
            sb.AppendLine("DTEND:" + item.DateEvent.AddHours(4).ToString("s"));
            sb.AppendLine("SUMMARY:" + item.Title);
            sb.AppendLine("LOCATION:" + item.Address);
            sb.Append("DESCRIPTION:" + item.Description);
            sb.AppendLine(" Click here to see the map and details: " + url);
            sb.AppendLine("PRIORITY:3");
            sb.AppendLine("END:VEVENT");
            sb.AppendLine("END:VCALENDAR");


            // convert string to stream
            byte[] byteArray = UTF8Encoding.Default.GetBytes(sb.ToString());
            using (var stream = new MemoryStream(byteArray))
            {
                return stream;
            }
        }

    }
}
